<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ::selection { background:#ff9632; color: rgb(61, 173, 238); } 
        ::-moz-selection { background:#ff9632;color: #000; } 
        ::-webkit-selection { background:#ff9632; color: #000; }
    </style>
</head>
<body>
    <div id='app'>
        <button v-for='(item,inedx) in ary' @click="handleClick(item.title)">{{item.title}}</button>
        <component :is="comp"></component>
    </div>
    <template id="news">
        <div>
            <div class='com'>新闻</div>
        </div>
    </template>
    <template id="happy">
        <div>
            <div class='com'>娱乐</div>
        </div>
    </template>
    <template id="sports">
        <div>
            <div class='com'>体育</div>
        </div>
    </template>
    <script src="../vue.js"></script>
    <script>
        let news={
            template:'#news'
        }
        let happy={
            template:'#happy'
        }
        let sports={
            template:'#sports'
        }
        new Vue({
            el:'#app',
            data () {
                return {
                    ary:[
                        {title:'新闻'},
                        {title:'娱乐'},
                        {title:'体育'},
                    ],
                    comp:'news',
                }
            },
            components: {
                news,
                happy,
                sports,
            },
            methods: {
                handleClick(ti){
                    if(ti=='新闻'){
                        this.comp='news';
                    }
                    else if(ti=='娱乐'){
                        this.comp='happy';
                    }
                    else if(ti=='体育'){
                        this.comp='sports';
                    }
                }
            }
        })
    </script>
</body>
</html>